package com.example.travel.service.impl;

import com.example.travel.entity.Admin;
import com.example.travel.entity.User;
import com.example.travel.mapper.LoginRegisterMapper;
import com.example.travel.service.ILoginRegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginRegisterService implements ILoginRegisterService {

    @Autowired
    private LoginRegisterMapper loginRegisterMapper;


    @Override
    public User login(User user) {
        return loginRegisterMapper.login(user);
    }

    @Override
    public int register(User user) {
        int isUsername = loginRegisterMapper.isRegister(user);
        int isEmail = loginRegisterMapper.isRegisterEmail(user);
        if(isUsername != 0){
            return 2;
        }
        if(isEmail != 0){
            return 3;
        }
        return loginRegisterMapper.register(user);
    }

    @Override
    public Admin admin_login(Admin admin) {
        return loginRegisterMapper.admin_login(admin);
    }
}
